<template>
    
    <!-- 组件的模板 -->
    <div class="page form-report">
        <ul class="form-list_2">
            <li v-for="list in lists" @click="gotoEdit(list.id)">
                <a class="bg-color touch flex" href="javascript:;">
                    <span class="bg_sprite icon"></span>
                    <div class="info">
                        <h3>{{list.title}}</h3>
                        <p>{{list.end_date}} 截止</p>
                    </div>
                </a>
            </li>
        </ul>
    </div>
    <empty :show-empty="lists && lists.length == 0" :msg="'暂无可填写表单'"></empty>

</template>

<script>
    /**
     *  引入工具类库 或 Native API
     *  example : import widget from 'gapi/widget'
     */

    import * as util from 'js/util.js'
    import cache from 'gapi/cache.js'
    import commonPage from 'clientApi/commonPage.js'
    import widget from 'gapi/widget.js'
    /**
     *  引入组件 以及 组件接口(Action)
     *  example : import Somecomponents from 'components/Somecomponents/Somecomponents'
     */
    import Empty from 'components/Empty/Empty'
    /**
     *  组件实例对象
     */
    export default {
        components: {
            Empty
        },
        data: function(){
            return{
                lists: '', //[]
                team_id: 0,
                project_id: 0
            }
        },
        vuex: {
            getters: {
                
            },
            actions: {

            }
        },
        methods: {
            /**
             * 初始化
             * @method init
             * @public
             * @return {Null} void
             */
            init (){
                this.team_id = util.getQueryString('team_id')
                this.project_id = util.getQueryString('project_id')
                cache.setCache('user_info', {
                    team_id: this.team_id,
                    project_id: this.project_id
                }, 100000)
                cache.setCache('KqCacheMessge', {
                    team_id: this.team_id,
                    project_id: this.project_id
                }, 100000)
                // alert(location.href)

                commonPage.loadPageStatus('loading')
                util.ajax({
                    url: '/form/list2',
                    type: 'GET',
                    data: {
                        team_id: this.team_id,
                        project_id: this.project_id
                    },
                    timeout: 10000,
                    success: (data) => {
                        commonPage.loadPageStatus('loadSuccess')
                        // success
                        // alert(JSON.stringify(data))
                        if(data.errno == 0){
                            this.lists = data.data
                        }else{
                            widget.toast(data.errmsg)
                            // alert(JSON.stringify(data))
                        }
                    },
                    error: (xhr, status) => {
                        commonPage.loadPageStatus('loadSuccess')
                        widget.toast('服务器异常')
                        // error
                    },
                    noNetwork: () => {
                        commonPage.loadPageStatus('loadSuccess')
                        // 无网络的回调
                        widget.toast('网络连接失败，请检查网络')
                    }
                })
                //权限信息
                util.ajax({
                    url: '/permission/application',
                    type: 'GET',
                    data: {
                        team_id: this.team_id,
                        project_id: this.project_id,
                        application_id: 3
                    },
                    timeout: 10000,
                    success: (data) => {
                        // success
                        // alert(JSON.stringify(data))
                        if(data.errno == 0){
                            cache.setCache('permission_info', data.data, 100000)
                        }else{
                            // alert(JSON.stringify(data))
                            // widget.toast('服务器异常')
                            widget.toast(data.errmsg)
                        }
                        commonPage.loadPageStatus('loadSuccess')
                    },
                    error: (xhr, status) => {
                        widget.toast('服务器异常')
                        commonPage.loadPageStatus('loadSuccess')
                        // error
                    },
                    noNetwork: () => {
                        // 无网络的回调
                        widget.toast('网络连接失败，请检查网络')
                        commonPage.loadPageStatus('loadSuccess')
                    }
                })
            },
            gotoEdit (id){
                commonPage.loadPageStatus('loading')
                util.ajax({
                    url: '/form/report/submit/check',
                    type: 'GET',
                    data: {
                        team_id: this.team_id,
                        project_id: this.project_id,
                        form_id: id
                    },
                    timeout: 10000,
                    success: (data) => {
                        // success
                        // alert(JSON.stringify(data))
                        if(data.errno == 0){
                            let encodeStr = encodeURIComponent(`form_id=${id}`)
                            location.href = `dmsaas://EditReportInfo?urdData=${encodeStr}`
                        }else if(data.errno == 22006){
                            widget.toast('当前暂时无法填写此表单，请稍后重试或联系管理员!')
                        }else if(data.errno == 22003){
                            widget.toast('该表单不允许重复提交,请删除已提交表单后重试!')
                        }else{
                            // widget.toast('服务器异常')
                            widget.toast(data.errmsg)
                        }
                        commonPage.loadPageStatus('loadSuccess')
                    },
                    error: (xhr, status) => {
                        widget.toast('服务器异常')
                        commonPage.loadPageStatus('loadSuccess')
                        // error
                    },
                    noNetwork: () => {
                        // 无网络的回调
                        widget.toast('网络连接失败，请检查网络')
                        commonPage.loadPageStatus('loadSuccess')
                    }
                })
                
            }
            // ,
            // changeTimeFormat(date){
            //     return date.replace(/-/g, '/')
            // }
        },
        created(){
            commonPage.updateTitleBar({
                //backAction: 'checkChange',    // 点击返回按钮的动作（即回调函数名称）
                // leftDisplay: false,            // 是否显示左按钮
                // leftText: '',                // 左按钮文案
                //leftAction: 'checkChange',    // 点击左按钮的动作（即回调函数名称）
                rightDisplay: false,            // 是否显示右按钮
                // rightText: '新增表单',            // 右按钮文案
                // rightAction: 'saveResume'    // 点击右按钮的文案（即回调函数名称）
            })
            this.init();
            window.loadData = (data) => {
                // console.log(data)
                commonPage.loadPageStatus('loading')
                util.ajax({
                    url: '/form/list2',
                    type: 'GET',
                    data: {
                        team_id: this.team_id,
                        project_id: this.project_id
                    },
                    timeout: 10000,
                    success: (data) => {
                        commonPage.loadPageStatus('loadSuccess')
                        // success
                        // alert(JSON.stringify(data))
                        if(data.errno == 0){
                            this.lists = data.data
                        }else{
                            widget.toast(data.errmsg)
                            // alert(JSON.stringify(data))
                        }
                    },
                    error: (xhr, status) => {
                        commonPage.loadPageStatus('loadSuccess')
                        widget.toast('服务器异常')
                        // error
                    },
                    noNetwork: () => {
                        commonPage.loadPageStatus('loadSuccess')
                        // 无网络的回调
                        widget.toast('网络连接失败，请检查网络')
                    }
                })
            }
        }
        
    }

    
</script>

<!-- CSS 样式 -->
<style src="../../node_modules/weui/dist/style/weui.css"></style>
<style src="../../static/css/common.css"></style>
<style src="../../static/css/form-report.css"></style>



